{extend name="public:layout" /}
{block name="title"}拷贝商品{/block}
{block name="head"}
{:widget('common/Form/icheckRes')}
{:widget('common/Form/ueditorRes')}
{:widget('common/Form/validRes')}
<script type="text/javascript">var sku_sn = "{:rand_string(8,1)}";</script>
<script type="text/javascript" src="/public/plugins/sku/sku-table.js"></script>
<script type="text/javascript" src="/public/plugins/template/template.js"></script>
<script type="text/javascript" src="/public/plugins/laydate/laydate.js"></script>
<style>
    .dropdown-menu {
        min-width: 65px;
    }
    .tab-pane{padding-top:10px;}
</style>
{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> <a href="{:url('index')}"> 商品列表</a></li>
                <li class="active">拷贝商品</li>
            </ol>
        </div>
        <div class="ibox-content">
            <form method="post" class="form-horizontal" id="form">
                <ul class="nav nav-tabs" role="tablist">
                    <li role="presentation" class="active">
                        <a href="#base" data-toggle="tab" role="tab">基本信息</a>
                    </li>
                    <li>
                        <a href="#extend" data-toggle="tab" role="tab">扩展信息</a>
                    </li>
                    <li>
                        <a href="#seo" data-toggle="tab" role="tab">SEO选项</a>
                    </li>
                </ul>
                <div class="tab-content">
                    <div class="tab-pane active" id="base">
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">商品名称</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" placeholder="请输入商品名称"
                                       name="goods_name" value="{$info.goods_name}" datatype="*"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">商品副标题</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" placeholder="请输入商品副标题"
                                       name="sub_title" value="{$info.sub_title}"/>
                            </div>
                            <label class="col-sm-2 control-label Validform_label">状态</label>
                            <div class="col-sm-4">
                                <label class="radio-inline i-checks">
                                    <input type="radio" name="is_on_sale" value="1"
                                           {eq name="info.is_on_sale" value="1"}checked{/eq}> 上架
                                </label>
                                <label class="radio-inline i-checks">
                                    <input type="radio" name="is_on_sale" value="0"
                                           {eq name="info.is_on_sale" value="0"}checked{/eq}> 下架
                                </label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">商品类目</label>
                            <div class="col-sm-4">
                                <select class="form-control" name="cid" id="cid">
                                    <option value="">请选择商品类目</option>
                                    {volist name="goodsCategory" id="vo"}
                                    <option value="{$vo.cid}" {eq name="info.cid" value="$vo['cid']" }selected{/eq}>
                                    {$vo._name}
                                    </option>
                                    {/volist}
                                </select>
                            </div>
                            <label class="col-sm-2 control-label Validform_label">商品单位</label>
                            <div class="clo-sm-4">
                                <div class="input-group">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                            选择 <span class="caret"></span></button>
                                        <ul class="dropdown-menu dropdown-menu-right">
                                            {volist name="unitList" id="unit"}
                                            <li><a href="javascript:;" onclick="$('#goodsUnit').val('{$unit}')">{$unit}</a></li>
                                            {/volist}
                                        </ul>
                                    </div>
                                    <input type="text" class="form-control" id="goodsUnit" name="goods_unit"
                                           value="{$info.goods_unit}"
                                           placeholder="请输入商品单位"/>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">产品相册</label>
                            <div class="col-sm-10">
                                {:widget('common/Form/moreImg',['album',$info['album'],$utype])}
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">商品品牌</label>
                            <div class="col-sm-4">
                                <select name="brand_id" id="brandId" class="form-control">
                                    <option value="">通用类型</option>
                                </select>
                            </div>
                            <label class="col-sm-2 control-label Validform_label">商品属性</label>
                            <div class="col-sm-4">
                                <label class="checkbox-inline i-checks">
                                    <input type="checkbox" name="is_commend" value="1"
                                           {eq name="info.is_commend" value="1"}checked{/eq} /> 推荐
                                </label>
                                <label class="checkbox-inline i-checks">
                                    <input type="checkbox" name="is_best" value="1"
                                           {eq name="info.is_best" value="1" }checked{/eq}/> 精品
                                </label>
                                <label class="checkbox-inline i-checks">
                                    <input type="checkbox" name="is_new" value="1"
                                           {eq name="info.is_new" value="1" }checked{/eq}/> 新品
                                </label>
                                <label class="checkbox-inline i-checks">
                                    <input type="checkbox" name="is_hot" value="1"
                                           {eq name="info.is_hot" value="1" }checked{/eq}/> 热销
                                </label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">商品定价</label>
                            <div class="col-sm-10">
                                <div id="attrHtml"></div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">商品介绍</label>
                            <div class="col-sm-10">
                                {:widget('common/Form/ueditor',['content',$info['content'],$utype])}
                            </div>
                        </div>
                    </div>
                    <div class="tab-pane" id="extend">
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">扩展属性</label>
                            <div class="col-sm-4">
                                <select name="extend_id" id="extendId" class="form-control">
                                    <option value="">通用类型</option>
                                    {volist name="extendList" id="vo"}
                                    <option value="{$vo.extend_id}" {eq name="info.extend_id" value="$vo['extend_id']" }selected{/eq}>
                                    {$vo.extend_name}
                                    </option>
                                    {/volist}
                                </select>
                            </div>
                            <div class="col-sm-4">
                                <p class="help-block">以加入商品扩展属性，比如：型号，年代，款式等</p>
                            </div>
                        </div>
                        <div id="extendHtml"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">商品促销</label>
                            <div class="col-sm-10" id="promotion">
                                <label class="radio-inline">
                                    <input type="radio" data-url="{:url('ShopPromotion/getHtml0')}" name="promotion_type"
                                           value="0" {eq name="info.promotion_type" value="0" } checked {/eq}> 普通商品
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" data-url="{:url('ShopPromotion/getHtml1')}" name="promotion_type"
                                           value="1" {eq name="info.promotion_type" value="1" } checked {/eq}> 预售商品
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" data-url="{:url('ShopPromotion/getHtml2')}" name="promotion_type"
                                           value="2" {eq name="info.promotion_type" value="2" } checked {/eq}> 限时抢购
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" data-url="{:url('ShopPromotion/getHtml3')}" name="promotion_type"
                                           value="3" {eq name="info.promotion_type" value="3" } checked {/eq}> 积分商品
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" data-url="{:url('ShopPromotion/getHtml4')}" name="promotion_type"
                                           value="4" {eq name="info.promotion_type" value="4" } checked {/eq}> 集采商品
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" data-url="{:url('ShopPromotion/getHtml5')}" name="promotion_type"
                                           value="5" {eq name="info.promotion_type" value="5" } checked {/eq}> 竞拍商品
                                </label>
                            </div>
                        </div>
                        <div id="promotionHtml"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">库存报警设置</label>
                            <div class="col-sm-1">
                                <input type="text" class="form-control" placeholder="请输入库存报警数量"
                                       name="alert_num" value="{$info.alert_num}" />
                            </div>
                            <div class="col-sm-3">
                                <p class="form-control-static">设置为0不提示</p>
                            </div>
                            <label class="col-sm-2 control-label Validform_label">销售量</label>
                            <div class="col-sm-1">
                                <input type="text" class="form-control" placeholder="请输入销售量"
                                       name="goods_sale_number" value="{$info.goods_sale_number}" />
                            </div>
                            <div class="col-sm-3">
                                <p class="form-control-static">作弊才用，一般不建议修改</p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">赠送积分</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" placeholder="请输入赠送积分"
                                       name="give_integral" value="{$info.give_integral}"/>
                            </div>
                            <div class="col-sm-4">
                                <p class="help-block">-1表示按商品等价赠送积分</p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">绑定模板</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" placeholder="请输入绑定模板"
                                       name="content_tpl" value="{$info.content_tpl}" datatype="*"/>
                            </div>
                            <label class="col-sm-2 control-label Validform_label">商品排序</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control"
                                       name="goods_sort" value="{$info.goods_sort}" datatype="n"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">基本属性</label>
                            <div class="col-sm-10">
                                {:widget('common/Form/extend',['goods_extend',$info['goods_extend']])}
                            </div>
                        </div>
                    </div>
                    <div class="tab-pane" id="seo">
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">商品关键词</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" placeholder="请输入商品关键词"
                                       name="keywords" value="{$info.keywords}"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">商品描述</label>
                            <div class="col-sm-10">
                                <textarea class="form-control" name="description" rows="3" placeholder="请输入商品描述">{$info.description}</textarea>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                        <button class="btn btn-primary"
                                onclick="ajaxSubForm();" type="submit">
                            保存内容
                        </button>
                        <a href="{:url('index')}" class="btn btn-white">取消</a>
                        <span id="validError"></span>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        iCheck();
        var dom=$('input:radio[name="promotion_type"]:checked');
        var url = $(dom).data('url');
        getAjax(url, {'goods_id':"{$info.goods_id}"}, function (html) {
            $('#promotionHtml').html(html);
        });
        //商品促销
        $("input[name='promotion_type']").on('click', function(){
            var url = $(this).data('url');
            getAjax(url, {'goods_id':"{$info.goods_id}"}, function (html) {
                $('#promotionHtml').html(html);
            })
        });

        function getdefault(th) {
            var url = $(th).data('url');
            getAjax(url, {}, function (html) {
                $('#promotionHtml').html(html);
            });
        }

        $('#extendId').change(function () {
            var extendId = $(this).val();
            getExtend(extendId, "{$info.goods_id}");
        });
        //销售树型及品牌
        $("#cid").change(function () {
            var cid = $(this).val();
            getBrand(cid);
            getAttr(cid);
        });
        $("#cid").trigger("change"); //加载触发
        $("#extendId").trigger("change"); //加载触发
    })
    /**
     * 获取指定栏目下对应品牌
     * @param cid
     */
    function getBrand(cid) {
        var InfoBrandId = "{$info.brand_id}";
        getAjax('{:url("getCidBrand")}', {cid: cid}, function (res) {
            $("#brandId").find("option").remove();
            if (res.length > 0) {
                $('#brandId').append('<option value="">请选择商品品牌</option>');
                for (var i = 0; i < res.length; i++) {
                    var selected = '';
                    if (InfoBrandId == res[i].brand_id) {
                        selected = 'selected';
                    }
                    $('#brandId').append('<option value="' + res[i].brand_id + '" ' + selected + '>' + res[i].brand_name + '</option>');
                }
            }
        })
    }
    /**
     * 获取指定扩展下html
     * @param extendId
     */
    function getExtend(extendId, goodsId) {
        if (extendId > 0) {
            getAjax('{:url("extend")}', {extend_id: extendId, goods_id: goodsId}, function (html) {
                $('#extendHtml').html(html);
            })
        } else {
            $('#extendHtml').empty();
        }
    }
    /**
     * 获取栏目绑定属性
     */
    function getAttr(cid) {
        getAjax('{:url("getAttr")}', {cid: cid}, function (html) {
            if(html!=''){
                $('#attrHtml').html(html);
                iCheck();
            }else{
                $('#attrHtml').html('');
            }
        })
    }
</script>
{/block}